package org.ru.mse10.cvis.upload;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.ru.mse10.cvis.util.CommonUtil;

/**
 * The Class CSVParser.
 */
public class CSVParser {

	/** The row handler. */
	private final CommonHandler<String> rowHandler = new UserCSVRowHandler();

	/**
	 * Parses the.
	 * 
	 * @param input
	 *            the input
	 */
	public void parse(InputStream input) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(input));
			String line = null;
			while ((line = br.readLine()) != null) {
				if (CommonUtil.isEmpty(line)) {
					continue;
				}
				rowHandler.handle(line);
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
